const axios =require('axios')
module.exports={
    namespaced:true,
    state:{
        orderData:[],
        orderDataOne:{}
    },
    mutations:{
        getorderData(state,data){
            state.orderData=data
        },
        getorderDataOne(state,data){
            state.orderDataOne=data
            // console.log("数据",state.orderDataOne)
        }
    },
    actions:{
        //获取全部
        async getOrderList(context){
            const {data}=await axios.get('/orders/getOrder')
            context.commit('getorderData',data)
        },
        //删除
        async deleteOrderListOne(context,Id){
            const {data}=await axios.post('/orders/deleteOrder',{_id:Id})
            context.dispatch('getOrderList')
        },
        //修改
        async updataOrderLiseAsync(context,Id){
            // console.log(111)
            const {data}=await axios.get('/orders/updataOrder',{params:{_id:Id}})
            console.log(data)
            context.commit("getorderDataOne",data[0])
        },
        //确认修改
        async chengeOrderData(context,newdata){
            // console.log(newdata)
            const {data}= await axios.post('/orders/setOrderData',newdata);
            if(data){
                window.location='http://localhost:8080/#/merchant/orderlist'
            }
        }
    },
    modules:{},
}